import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { ApiProperty, ApiHideProperty } from '@nestjs/swagger';
import { Book } from '../../book/entities/book.entity';
import { User } from '../../user/entities/user.entity';

@Entity('comments')
export class Comment {
  @PrimaryGeneratedColumn('uuid')
  @ApiProperty({ description: '评论ID' })
  id: string;

  @Column({ type: 'text' })
  @ApiProperty({ description: '评论内容' })
  content: string;

  @Column({ type: 'int', default: 0 })
  @ApiProperty({ description: '评分（0-5）' })
  rating: number;

  @ApiHideProperty()
  @ManyToOne(() => Book, book => book.id, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'book_id' })
  book: Book;

  @Column({ nullable: false })
  @ApiProperty({ description: '图书ID' })
  book_id: string;

  @ApiHideProperty()
  @ManyToOne(() => User, user => user.id)
  @JoinColumn({ name: 'user_id' })
  user: User;

  @Column({ nullable: false })
  @ApiProperty({ description: '用户ID' })
  user_id: string;

  @Column({ default: true })
  @ApiProperty({ description: '是否显示' })
  is_visible: boolean;

  @CreateDateColumn()
  @ApiProperty({ description: '创建时间' })
  created_at: Date;

  @UpdateDateColumn()
  @ApiProperty({ description: '更新时间' })
  updated_at: Date;
}